package com.songlanyun.modules.account.model.vo;

import cn.afterturn.easypoi.excel.annotation.Excel;
import cn.hutool.core.util.DesensitizedUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.ReUtil;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.songlanyun.common.drive.ValueObject;
import com.songlanyun.common.enums.GoodsConstant;
import com.songlanyun.common.enums.MemberConstant;
import com.songlanyun.common.validator.group.AppGroup;
import com.songlanyun.common.validator.group.AppLoginGroup;
import com.songlanyun.common.validator.group.WxGroup;
import com.songlanyun.common.validator.group.WxLoginGroup;
import com.songlanyun.modules.account.entity.AccountEntity;
import com.songlanyun.modules.account.entity.UserInfoEntity;
import com.songlanyun.modules.account.service.AccountService;
import com.songlanyun.modules.account.service.UserInfoService;
import com.songlanyun.modules.rabbitmq.util.SpringContextUtil;
import lombok.Data;
import org.apache.commons.lang.StringUtils;
import org.hibernate.validator.constraints.Length;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Pattern;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;

@Data
public class AccountVO implements Serializable, ValueObject {

    /**
     *
     */
    private Long id;

    /**
     * 是否是线下店长
     */
    private Integer oflineShopowner;

    //团队等级
    private Integer teamGrade;

    //董事等级
    private Integer directorGrade;

    /**
     * 手机号
     */
    @Excel(name = "用户手机号", orderNum = "1", width = 20)
    private String mobile;

    /**
     * 脱敏
     *
     * @return
     */
    public String getMobileDesensitized() {
        if (StringUtils.isNotEmpty(this.mobile)) {
            return DesensitizedUtil.mobilePhone(this.mobile);
        }
        return this.mobile;
    }

    /**
     * 邀请码
     */
    private String invitationCode;
    /**
     * 昵称
     */
    @Excel(name = "用户昵称", orderNum = "2", width = 20)
    private String nickname;

    /**
     * 昵称脱敏
     */
    public String getNicknameDesensitized() {
        if (StringUtils.isNotEmpty(this.nickname)) {
            return DesensitizedUtil.chineseName(this.nickname);
        }
        return this.nickname;
    }


    /**
     * 头像
     */
    private String headPhoto;
    /**
     * 余额
     */
    @Excel(name = "余额", orderNum = "3", width = 15)
    private BigDecimal balance;
    /**
     * 兑换券
     */
    private BigDecimal voucher;
    /**
     * 可用积分
     */
    @Excel(name = "可用积分", orderNum = "4", width = 15)
    private BigDecimal integralAble;
    /**
     * 贡献值
     */
    @Excel(name = "贡献值", orderNum = "5", width = 15)
    private BigDecimal commissionAble;

    /**
     * 消费总金额
     */
    @Excel(name = "消费总金额", orderNum = "6", width = 20)
    private BigDecimal totalAmount;
    /**
     * '锁定状态（0是未锁定可以正常使用，1锁定后不能使用'
     */
    private Integer lockStatus;
    /**
     * 用户在当前商家店的会员等级名（角色）
     */
    private String roleName;
    /**
     * 等级编号
     */
    private String roleCode;
    /**
     * 用户在当前商家的总消费
     */
    private BigDecimal totalConsumptions;

    /**
     * 是否是网红
     */
    private Boolean isCelebrity;

    /**
     * 是否是商家
     */
    private Boolean isShop;

    /**
     * 推荐会员·
     */
    private Long parentUserId;

    public void loadParentUser() {
        if (parentUserId != null) {
            AccountService accountService = (AccountService) SpringContextUtil.getBean("yxtAccountService");
            UserInfoService userInfoService = (UserInfoService) SpringContextUtil.getBean("yxtUserInfoService");
            AccountEntity account = accountService.getById(this.parentUserId);
            UserInfoEntity userInfo = userInfoService.getById(this.parentUserId);
            //设置推荐会员手机号
            if (account != null) {
                this.parentUserMobile = account.getMobile();
            }
            //设置推荐会员昵称
            if (userInfo != null) {
                this.parentUserName = ObjectUtil.isNotEmpty(userInfo.getRealName()) ? userInfo.getRealName() : userInfo.getNickname();
            }
        }
    }

    /**
     * 推荐会员昵称
     */
    @Excel(name = "推荐会员昵称", orderNum = "7", width = 20)
    private String parentUserName;

    /**
     * 推荐会员手机号
     */
    @Excel(name = "推荐会员手机号", orderNum = "8", width = 20)
    private String parentUserMobile;



    /**
     * 是否被激活
     */
    private Boolean activating = false;

    /**
     * 最后被激活的时间
     */
    private Date lastActivatingTime;


    private Date createTime;

    /**
     * 等级
     */
    private MemberConstant.MemberGrade grade;


}
